package com.org.any.autocar;

import com.autocar.reader.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.PluginState;
import android.widget.ImageView;

public class WebGouMaiActivity extends BaseActivity {
	WebView webView = null;
	private ImageView back = null;
	private ImageView backWeb = null;
	private ImageView qianWeb = null;
	private ImageView refresh = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//
		setContentView(R.layout.web_goumai);
		String url = getIntent().getStringExtra("url");
		Log.i("test", "url" + url);
		webView = (WebView) findViewById(R.id.web);
		this.back = (ImageView) findViewById(R.id.back);
		this.backWeb = (ImageView) findViewById(R.id.back_web);
		this.qianWeb = (ImageView) findViewById(R.id.qian_web);
		this.refresh = (ImageView) findViewById(R.id.refresh);

		back.setOnClickListener(backClick);
		backWeb.setOnClickListener(back_webClick);
		qianWeb.setOnClickListener(qian_webClick);
		refresh.setOnClickListener(refreshClick);

		webView.setWebViewClient(new WebGouMaiView(this));
		WebSettings settings = webView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setPluginState(PluginState.OFF);
		settings.setAppCacheEnabled(true);
		settings.setPluginsEnabled(true);
		webView.loadUrl(url);
	}

	OnClickListener backClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			back();
		}
	};

	public void back() {
		this.finish();
		overridePendingTransition(R.anim.fade_in, R.anim.right_out_anim);
	}

	OnClickListener back_webClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			webView.goBack();
		}
	};

	OnClickListener qian_webClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			webView.goForward();
		}
	};

	OnClickListener refreshClick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			webView.reload();
		}
	};
	
	public class WebGouMaiView extends WViewClient{

		public WebGouMaiView(Context context) {
			super(context);
			// TODO Auto-generated constructor stub
		}
		
		@Override
		public void onPageFinished(WebView view, String url) {
			// TODO Auto-generated method stub
			super.onPageFinished(view, url);
			hideLoadPb();
		}
		
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			// TODO Auto-generated method stub
			super.onPageStarted(view, url, favicon);
			showLoadPb();
		}
		
	}
}
